package com.gshg.log.cleanlog.quartz;



import com.gshg.log.cleanlog.quartz.JobDetail.LogFileCleanJobDetail;
import org.apache.commons.lang3.StringUtils;
import org.quartz.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class QuartzClusterConfigure {

    @Value("${quartz.log-clean.corn}")
    String logFileCleanCorn;


    ///----分界线---------------------------------------------------------------------------

    @Bean
    public JobDetail LogFileCleanQuartzDetail() {

        return JobBuilder.newJob(LogFileCleanJobDetail.class)//需要修改
                .withIdentity("logFileCleanQuartz")//需要修改
                .storeDurably().build();
    }

    // 把jobDetail注册到Cron表达式的trigger上去
    @Bean
    public Trigger logFileCleanQuartzDetailJobTrigger() {

        if(StringUtils.isEmpty(logFileCleanCorn)){
            logFileCleanCorn="0 10 2 * * ?";
        }

        CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(logFileCleanCorn); //需要修改，可使用yaml配置

        return TriggerBuilder.newTrigger()
                .forJob(LogFileCleanQuartzDetail())   //需要修改
                .withIdentity("logFileCleanQuartzDetailJobTrigger")
                .withSchedule(cronScheduleBuilder)
                .build();
    }

    ///----分界线---------------------------------------------------------------------------

}
